Defines an environment in which scripts can execute. More...
Public Member Functions | |
| Environment () | |
| ~Environment () | |
| const ExecutionResult & | getLastExecutionResult () const |
| const char * | getName () const |
| void | setEnvironmentFor (INTERPRETER interpretType) |
| void | setName (const char *name) |
| bool | execute (const Script &script) |
| void | requestGarbageCollection () |
| void | setVar (const char *name, bool value) |
| void | setVar (const char *name, int value) |
| void | setVar (const char *name, float value) |
| void | setVar (const char *name, double value) |
| void | setVar (const char *name, const char *value) |
| void | setVar (const char *name, const ScriptObjectReference &value) |
| void | setObject (const char *name, const char *userTypeName, void *value) |
| bool | isVarSet (const char *name) |
| bool | getVar (const char *name, bool defaultValue) |
| int | getVar (const char *name, int defaultValue) |
| float | getVar (const char *name, float defaultValue) |
| double | getVar (const char *name, double defaultValue) |
| const char * | getVar (const char *name, const char *defaultValue) |
| ScriptObjectReference | getVar (const char *name) |
| void * | getObject (const char *name, const char *userTypeName=nullptr) |
| ScriptObjectReference | getScriptFunction (const char *name) |
| Function * | setFunc (const char *name) |
| bool | isFuncSet (const char *name) |
| Function * | getFunc (const char *name) |
| UserType * | setUserType (const char *name) |
| bool | isUserTypeSet (const char *name) |
| UserType * | getUserType (const char *name) |
| Namespace * | setNamespace (const char *name) |
| bool | isNamespaceSet (const char *name) |
| Namespace * | getNamespace (const char *name) |
| bool | callScriptFunction (const ScriptObjectReference &reference, const DataStack &args, DataStack &expectedOutput) |
| std::vector< unsigned char > | serializeScriptObject (const ScriptObjectReference &reference, bool forwardUserDataOwnership=false) |
| ScriptObjectReference | deserializeScriptObject (const std::vector< unsigned char > &object) |
Defines an environment in which scripts can execute.
It can be seen as a context in which structures and objects can be defined and accessed.
| nkScripts::Environment::Environment | ( | ) |
Constructor.
| nkScripts::Environment::~Environment | ( | ) |
Destructor.
| const ExecutionResult& nkScripts::Environment::getLastExecutionResult | ( | ) | const |
| const char* nkScripts::Environment::getName | ( | ) | const |
| void nkScripts::Environment::setEnvironmentFor | ( | INTERPRETER | interpretType | ) |
Sets the interpreter the environment should be ready for.
| interpretType | The type of interpreter to use. |
| void nkScripts::Environment::setName | ( | const char * | name | ) |
Sets the name of the environment.
| name | The name to set. |
| bool nkScripts::Environment::execute | ( | const Script & | script | ) |
Requests the execution of a script within the environment.
| script | The script to execute. |
| void nkScripts::Environment::requestGarbageCollection | ( | ) |
Requests a garbage collection within the environment.
| void nkScripts::Environment::setVar | ( | const char * | name, |
| bool | value | ||
| ) |
Sets a variable within the environment.
| name | The name of the variable to set. |
| value | The value to assign to it. |
| void nkScripts::Environment::setVar | ( | const char * | name, |
| int | value | ||
| ) |
Sets a variable within the environment.
| name | The name of the variable to set. |
| value | The value to assign to it. |
| void nkScripts::Environment::setVar | ( | const char * | name, |
| float | value | ||
| ) |
Sets a variable within the environment.
| name | The name of the variable to set. |
| value | The value to assign to it. |
| void nkScripts::Environment::setVar | ( | const char * | name, |
| double | value | ||
| ) |
Sets a variable within the environment.
| name | The name of the variable to set. |
| value | The value to assign to it. |
| void nkScripts::Environment::setVar | ( | const char * | name, |
| const char * | value | ||
| ) |
Sets a variable within the environment.
| name | The name of the variable to set. |
| value | The value to assign to it. |
| void nkScripts::Environment::setVar | ( | const char * | name, |
| const ScriptObjectReference & | value | ||
| ) |
Sets a variable within the environment.
| name | The name of the variable to set. |
| value | The value to assign to it. |
| void nkScripts::Environment::setObject | ( | const char * | name, |
| const char * | userTypeName, | ||
| void * | value | ||
| ) |
Sets an object within the environment.
| name | The name of the object to set. |
| userTypeName | The type name of the user data to set. |
| value | The user data to assign to it. |
| bool nkScripts::Environment::isVarSet | ( | const char * | name | ) |
Checks whether a variable is existing in the environment.
| name | The name of the variable to check. |
| bool nkScripts::Environment::getVar | ( | const char * | name, |
| bool | defaultValue | ||
| ) |
Retrieves a variable, if it exists.
| name | The name of the variable to retrieve the value from. |
| defaultValue | The default value to return if no variable of this name exists, or if the variable is not from requested type. |
| int nkScripts::Environment::getVar | ( | const char * | name, |
| int | defaultValue | ||
| ) |
Retrieves a variable, if it exists.
| name | The name of the variable to retrieve the value from. |
| defaultValue | The default value to return if no variable of this name exists, or if the variable is not from requested type. |
| float nkScripts::Environment::getVar | ( | const char * | name, |
| float | defaultValue | ||
| ) |
Retrieves a variable, if it exists.
| name | The name of the variable to retrieve the value from. |
| defaultValue | The default value to return if no variable of this name exists, or if the variable is not from requested type. |
| double nkScripts::Environment::getVar | ( | const char * | name, |
| double | defaultValue | ||
| ) |
Retrieves a variable, if it exists.
| name | The name of the variable to retrieve the value from. |
| defaultValue | The default value to return if no variable of this name exists, or if the variable is not from requested type. |
| const char* nkScripts::Environment::getVar | ( | const char * | name, |
| const char * | defaultValue | ||
| ) |
Retrieves a variable, if it exists.
| name | The name of the variable to retrieve the value from. |
| defaultValue | The default value to return if no variable of this name exists, or if the variable is not from requested type. |
| ScriptObjectReference nkScripts::Environment::getVar | ( | const char * | name | ) |
Retrieves a variable, if it exists.
| name | The name of the variable to retrieve the value from. |
| void* nkScripts::Environment::getObject | ( | const char * | name, |
| const char * | userTypeName = nullptr |
||
| ) |
Retrieves an object if it exists.
| name | The name of the variable to retrieve the object from. |
| userTypeName | If needed, the type name can be specified to ensure pointer returned is of the right type. |
| ScriptObjectReference nkScripts::Environment::getScriptFunction | ( | const char * | name | ) |
Retrieves a reference over a function defined in the scripting environment.
| name | The name of the function to retrieve. |
| Function* nkScripts::Environment::setFunc | ( | const char * | name | ) |
Sets a function within the environment.
| name | The name of the function to set. |
| bool nkScripts::Environment::isFuncSet | ( | const char * | name | ) |
Checks whether a function is existing within the environment.
| name | The name of the function to check. |
| Function* nkScripts::Environment::getFunc | ( | const char * | name | ) |
| name | The name of the function to retrieve. |
| UserType* nkScripts::Environment::setUserType | ( | const char * | name | ) |
Sets a user type within the environment.
| name | The name of the user type to set. It is possible to shortcut into namespaces using a syntax like ns0::ns1::UserTypeName. |
| bool nkScripts::Environment::isUserTypeSet | ( | const char * | name | ) |
Checks whether a user type is existing within the environment.
| name | The name of the user type to check. |
| UserType* nkScripts::Environment::getUserType | ( | const char * | name | ) |
| name | The name of the user type to retrieve. |
| Namespace* nkScripts::Environment::setNamespace | ( | const char * | name | ) |
Sets a namespace within the environment.
| name | The name of the namespace to set. |
| bool nkScripts::Environment::isNamespaceSet | ( | const char * | name | ) |
Checks whether a namespace is existing within the environment.
| name | The name of the namespace to check. |
| Namespace* nkScripts::Environment::getNamespace | ( | const char * | name | ) |
| name | The name of the namespace to retrieve. |
| bool nkScripts::Environment::callScriptFunction | ( | const ScriptObjectReference & | reference, |
| const DataStack & | args, | ||
| DataStack & | expectedOutput | ||
| ) |
Calls a script function from the C++ environment.
| reference | The function reference, in the environment. |
| args | The arguments to provide to the function, in a stack. |
| expectedOutput | A ready stack that will receive the output of the called function. |
| std::vector<unsigned char> nkScripts::Environment::serializeScriptObject | ( | const ScriptObjectReference & | reference, |
| bool | forwardUserDataOwnership = false |
||
| ) |
Serializes an object from the environment into a binary buffer. This can be used to pass a script object from one environment to another, for instance.
| reference | The reference in the environment of the object to serialize. |
| forwardUserDataOwnership | Whether the user data, defined by user types, should also forward their ownership to the serialization object (true) or not (false). \ This will ultimately transmit the ownsership to the environment where it is deserialized. |
| ScriptObjectReference nkScripts::Environment::deserializeScriptObject | ( | const std::vector< unsigned char > & | object | ) |
Deserializes a binary buffer into a new object within the environment.
| object | The serialized binary buffer to deserialize. |